package com.java.clone;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Student implements Cloneable,Serializable{
//设置属性
	private String stuame;
	private int stuage;
	//设置引用数据类型的teacher
	private Teacher teacher;
	
	public Student(String stuame, int stuage, Teacher teacher) {
		super();
		this.stuame = stuame;
		this.stuage = stuage;
		this.teacher = teacher;
	}
	public Student() {
		super();
		// TODO Auto-generated constructor stub
	}
	@Override
	public String toString() {
		return "Student [stuame=" + stuame + ", stuage=" + stuage + ", teacher=" + teacher + "]";
	}
	public String getStuame() {
		return stuame;
	}
	public void setStuame(String stuame) {
		this.stuame = stuame;
	}
	public int getStuage() {
		return stuage;
	}
	public void setStuage(int stuage) {
		this.stuage = stuage;
	}
	public Teacher getTeacher() {
		return teacher;
	}
	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}
	//行为
	public Student clone() {
		Student student=null;
		try {
			//ByteArrayOutputStream输出流对象，用于临时缓存输出流内容
			ByteArrayOutputStream bos=new ByteArrayOutputStream();	
			ObjectOutputStream oos=new ObjectOutputStream(bos);
			//写对象
			oos.writeObject(this);
			ObjectInputStream ois=new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
			//读对象
			student=(Student) ois.readObject();
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return student;
		
	}
	
}
